package com.ten.teacher.service.impl;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ten.common.core.entity.EduTeacher;
import com.ten.common.core.entity.TbShouCangTeacher;
import com.ten.common.core.vo.Result;
import com.ten.teacher.dao.AttentionTeacherDao;
import com.ten.teacher.service.AttentionTeacherService;
import com.ten.teacher.vo.GuanZhuVo;
import org.aspectj.weaver.ast.Var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：Wqw
 * @date ：Created in 2022/12/28 23:26
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class AttentionTeacherServiceImpl implements AttentionTeacherService {
    @Autowired
    private AttentionTeacherDao attentionTeacherDao;


    /**
     * 通过会员id连表查询会员关注的讲师信息*/
    @Override
    public Result<EduTeacher> findAllByMemberId(String memberId) {
        List<EduTeacher> attentionTeacher = attentionTeacherDao.findAllByMemberId(memberId);
        return new Result(200,"查询成功",attentionTeacher);
    }

    /**
     * 取消关注,通过对应讲师id*/
    @Override
    public Result deleteAttentionById(GuanZhuVo guanZhuVo) {
        QueryWrapper<TbShouCangTeacher> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",guanZhuVo.getTeacherId());
        wrapper.eq("member_id",guanZhuVo.getMemberId());
        int delete = attentionTeacherDao.delete(wrapper);
        if (delete==1){
            return new Result(200,"已取消关注");
        }
        return new Result(500,"操作失败");
    }

    /**点开课程查询是否关注该老师
     * 从而显示 已关注 未关注*/
    @Override
    public Result findTeacherByStatus(GuanZhuVo guanZhuVo) {
        QueryWrapper<TbShouCangTeacher> wrapper = new QueryWrapper<>();
        wrapper.eq("member_id",guanZhuVo.getMemberId());
        wrapper.eq("teacher_id",guanZhuVo.getTeacherId());
        TbShouCangTeacher tbShouCangTeacher = attentionTeacherDao.selectOne(wrapper);
        if (tbShouCangTeacher!=null){
            return new Result(200,"已关注",1);
        }
        return new Result(500,"未关注",0);
    }

    /**点开课程
     * 点击未关注关注该讲师*/
    @Override
    public Result insertAttentionTeacherByMemberId(GuanZhuVo guanZhuVo) {
        TbShouCangTeacher attentionTeacher = new TbShouCangTeacher();
        long id = IdUtil.getSnowflakeNextId();
        attentionTeacher.setId(id+"");
        attentionTeacher.setMemberId(guanZhuVo.getMemberId());
        attentionTeacher.setTeacherId(guanZhuVo.getTeacherId());
        int insert = attentionTeacherDao.insert(attentionTeacher);
        if (insert==1){
            return new Result(200,"成功关注");
        }
        return new Result(500,"关注失败");
    }
}
